package com.xzit.rcpyxt.controller;

import com.xzit.rcpyxt.constant.MessageCode;
import com.xzit.rcpyxt.dto.*;
import com.xzit.rcpyxt.entity.Attendance;
import com.xzit.rcpyxt.entity.Historical;
import com.xzit.rcpyxt.entity.StudentAttendance;
import com.xzit.rcpyxt.service.AttendanceService;
import com.xzit.rcpyxt.utils.PageUtil;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(value = "/attendance")
public class AttendanceController {

    @Autowired
    private AttendanceService attendanceService;

    @ApiOperation(value = "点名")
    @RequestMapping(value = "/rollCall", method = RequestMethod.POST)
    public ResultModel rollCall (@RequestBody RollCallDto attendance) {
        attendanceService.rollCall(attendance);
        return new ResultModel(MessageCode.OK);
    }

    @ApiOperation(value = "保存考勤")
    @RequestMapping(value = "/saveAttendce", method = RequestMethod.POST)
    public ResultModel saveAttendce (@RequestBody SaveAttendanceDto attendance) {
        attendanceService.insertByAttendance(attendance);
        return new ResultModel(MessageCode.OK);
    }

    @ApiOperation(value = "获取老师的考勤列表", response = Attendance.class)
    @RequestMapping(value = "/findByAttendanceList", method = RequestMethod.GET)
    public ResultModel findByAttendanceList(AttendanceListRequest attendanceDto) {
        PageUtil byClassList = attendanceService.findByAttendanceList(attendanceDto);
        return new ResultModel(MessageCode.OK, byClassList);
    }

    @ApiOperation(value = "获取考勤明细", response = StudentAttendance.class)
    @RequestMapping(value = "/findByAttendanceUserList", method = RequestMethod.GET)
    public ResultModel findByAttendanceUserList(StudentAttendanceListRequest attendanceDto) {
        PageUtil byClassList = attendanceService.findByAttendanceUserList(attendanceDto);
        return new ResultModel(MessageCode.OK, byClassList);
    }

    @ApiOperation(value = "获取历史记录", response = Historical.class)
    @RequestMapping(value = "/findByHistoricalList", method = RequestMethod.GET)
    public ResultModel findByHistoricalList(HistoricalListRequestDto attendanceDto) {
        PageUtil byClassList = attendanceService.findByHistoricalList(attendanceDto);
        return new ResultModel(MessageCode.OK, byClassList);
    }

}